package com.just.springbootsecurity.security;

import com.just.springbootsecurity.dao.SysUserRepository;
import com.just.springbootsecurity.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class CustomUserService implements UserDetailsService {
    @Autowired
    private SysUserRepository sysUserRepository;
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        SysUser sysUser=sysUserRepository.findByUsername(s);
        if(sysUser==null){
            throw new UsernameNotFoundException("用户不存在");
        }
        return sysUser;
    }
}
